﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using Entity;
using DataControls;
namespace GiaoVien_QuanLy_DeTai
{
    public partial class REPORT_LUONGGD_Form : Form
    {
        public REPORT_LUONGGD_Form()
        {
            InitializeComponent();
        }

        private void REPORT_LUONGGD_Form_Load(object sender, EventArgs e)
        {
            txtNamHoc.Text = DateTime.Now.Year.ToString();
            this.reportLuongGD.RefreshReport();
        }

        private void btnBaoCao_Click(object sender, EventArgs e)
        {
            int nh = 0;
            if (nmHocKi.Value <= 0 || nmHocKi.Value >= 20)
            {
                MessageBox.Show("Ban nhap hoc ki sai");
                return;
            }
            else
                try
                {
                    if ((nh = Convert.ToInt16(txtNamHoc.Text)) <= 1990)
                    {
                        MessageBox.Show("Ban nhap nam hoc chua chinh xac");
                    }
                    else
                    {
                        SqlConnection cnn = new SqlConnection(" Server = COLDBOY-MSI ;"
                                                            + " Database = CVHT_HDDT;"
                                                            + " Integrated Security = True");

                        SqlDataAdapter adapter = new SqlDataAdapter("SELECT G.TENGV, B.* FROM BANGLUONGGD B, GIAOVIEN G WHERE G.MAGV = B.MAGV"+
                                                                                    " AND HOCKI=" + (int)nmHocKi.Value +
                                                                                    "AND NAMHOC=" + nh, cnn);
                        DataSet ds = new DataSet();
                        adapter.Fill(ds, "BANGLUONGGD");

                        //load report
                        LUONGGD_Report rp = new LUONGGD_Report();
                        rp.SetDataSource(ds);
                        reportLuongGD.ReportSource = rp;
                        reportLuongGD.Refresh();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Nhập hocki/năm. \n" + ex.Message);
                    return;
                }
        }
    }
}
